#!/bin/bash
# $Id: init 718 2010-08-24 03:14:54Z ant_code $

PATH=/bin:/usr/bin:/sbin:/usr/sbin:.
export PATH
HOME=/root
export HOME

/bin/echo "/init ...."
/bin/hostname mostaza

# Mount 
/bin/mount -v proc /proc -n -t proc
/bin/mount -v sysfs /sys -n -t sysfs
#/bin/mount -t tmpfs -o size=64M  mdev /dev
mkdir -p /dev/pts
mount -t devpts devpts /dev/pts

mdev -s

ln -s /proc/mounts /etc/mtab
ln -s /usr/bin/killall /bin/killall

/sbin/syslogd -S
/sbin/klogd -c 3

test -x /sbin/ldconfig && /sbin/ldconfig

. /etc/scripts/env
. /etc/scripts/common.fn
. /etc/scripts/common.disks.fn

export running_mode=installer
echo $running_mode > $running_mode_file

mdev -s
mount_media && /etc/scripts/make-kernel-links.sh

# rc.d
/etc/rc.d/rc.udev start
if [ ! -f /var/tmp/cdrom_device ]; then
	_msg "\n\n Trying to remount CDROM ...\n "
	mount_media && /etc/scripts/make-kernel-links.sh
	/etc/rc.d/rc.udev restart
fi

# rng-tools; XXX slackware 12.1 - udev
if [ -L /dev/hw_random ]; then
	_msg "Starting rngd"
	/usr/local/sbin/rngd -b -r /dev/hw_random
fi

# cmdline
if [ "$(grep nologinst /proc/cmdline)" ]; then
	rm -f /var/log/inst.log
	ln -s /dev/null /var/log/inst.log
fi

if $(grep -q "tz=" /proc/cmdline) ; then
	tz="$(cat /proc/cmdline|tr [[:blank:]] "\n"|grep "tz=" |cut -f2 -d"=")"
	gzip -dc /etc/files/timezones.gz|grep -q $tz && echo $tz > $install_timezone
fi

if ! $(grep -q nomouse /proc/cmdline) ; then
	/sbin/modprobe psmouse 
	mousetype="$(cat /proc/cmdline|tr [[:blank:]] "\n"|grep "mouse="|cut -f2 -d"=")"
	/usr/sbin/gpm -m /dev/mouse -t ${mousetype:-imps2}
fi

# installation start time
date > $install_start_time

# fancy font
if [ -f /mostaza/files/misc/ter-v14n.psf -a ! "$(grep noff /proc/cmdline 2>/dev/null)" ]; then
	loadfont < /mostaza/files/misc/ter-v14n.psf
fi

# skeleton
touch $gui_switch $install_timezone $gui_permanent_switch $simple_menu_edit_done_list
echo 0 > $disk_commit_switch_running

# autoinstall / interactive install
if [ "$(grep auto /proc/cmdline)" ]; then
	export running_mode=autoinstall
	. /etc/scripts/autoinstall.fn
	echo "0" > $gui_switch
	autoinstall
else
	export running_mode=installer
	while true; do
		/usr/bin/screen -S $(hostname) -t $(hostname)
	done
fi

# vim: ts=2 syn=sh
# /init end
